/* =============================================
 * Project: fsutil
 * =============================================
 * Package: com.pti.fsc.common.vo
 *
 *
 * Copyright 2017 Premium Technology, Inc. All rights reserved.
 * PremiumIT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * WWW: http://www.premiumIT.com
 * Contact us: info@premiumIT.com
 * =============================================
 */
package com.pti.waf.util.ui;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pti.util.StringUtil;

/**
 * @author llu
 * 
 */
public class FormConfig implements Serializable {
	private static final long serialVersionUID = 6165129072845942019L;
	private String name;
	/*
	 * group the fields of the form
	 */
	private List<GridGroup> gridGroups;
	/*
	 * configure the group
	 */
	private Map<String, GridGroupConfig> gridGroupConfigs;
	/*
	 * configure the filed grid
	 */
	private Map<String, GridConfig> gridConfigs;

	/*
	 * button groups configuration
	 */
	private Map<String, ButtonConfig> buttonConfigs;
	/*
	 * table columns configuration
	 */
	private Map<String, TableConfig> tableConfigs;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<GridGroup> getGridGroups() {
		return gridGroups;
	}

	public void setGridGroups(List<GridGroup> gridGroups) {
		this.gridGroups = gridGroups;
	}

	public Map<String, GridGroupConfig> getGridGroupConfigs() {
		return gridGroupConfigs;
	}

	public void setGridGroupConfigs(Map<String, GridGroupConfig> gridGroupConfigs) {
		this.gridGroupConfigs = gridGroupConfigs;
	}

	public Map<String, GridConfig> getGridConfigs() {
		return gridConfigs;
	}

	public void setGridConfigs(Map<String, GridConfig> gridConfigs) {
		this.gridConfigs = gridConfigs;
	}

	public Map<String, ButtonConfig> getButtonConfigs() {
		return buttonConfigs;
	}

	public void setButtonConfigs(Map<String, ButtonConfig> buttonConfigs) {
		this.buttonConfigs = buttonConfigs;
	}

	public Map<String, TableConfig> getTableConfigs() {
		return tableConfigs;
	}

	public void setTableConfigs(Map<String, TableConfig> tableConfigs) {
		this.tableConfigs = tableConfigs;
	}

	public GridConfig addGridConfig(String gridName) {
		if (StringUtil.isEmpty(gridName)) {
			return null;
		}
		GridConfig gridConfig = new GridConfig();
		gridConfig.setName(gridName);
		if (gridConfigs == null) {
			gridConfigs = new HashMap<String, GridConfig>();
			gridConfigs.put(gridName, gridConfig);
		} else {
			gridConfigs.put(gridName, gridConfig);
		}
		return gridConfigs.get(gridName);
	}

	public GridGroupConfig addGridGroupConfig(String groupName) {
		if (StringUtil.isEmpty(groupName)) {
			return null;
		}
		GridGroupConfig groupConfig = new GridGroupConfig();
		groupConfig.setName(groupName);
		if (gridGroupConfigs == null) {
			gridGroupConfigs = new HashMap<String, GridGroupConfig>();
			gridGroupConfigs.put(groupName, groupConfig);
		} else {
			gridGroupConfigs.put(groupName, groupConfig);
		}
		return gridGroupConfigs.get(groupName);
	}

	public GridGroup addGridGroup(String groupName) {
		GridGroup group = null;
		if (gridGroups == null) {
			gridGroups = new ArrayList<GridGroup>();
			group = new GridGroup();
			group.setName(groupName);
			gridGroups.add(group);
		} else {
			for (GridGroup gridGroup : gridGroups) {
				if (StringUtil.isEmpty(gridGroup.getName())) {
					if (StringUtil.isEmpty(groupName)) {
						group = gridGroup;
						break;
					}
				} else if (gridGroup.getName().equals(groupName)) {
					group = gridGroup;
					break;
				}
			}
			if (group == null) {
				group = new GridGroup();
				group.setName(groupName);
				gridGroups.add(group);
			}
		}
		return group;
	}
}
